namespace Admin2025.Domain.Entities.App;


public class AppRole : EntityBase
{
    // 角色名称
    public string RoleName { get; set; } = null!;
    // 角色描述（可选）
    public string? Description { get; set; }
    // 角色拥有的权限
    public ICollection<AppPermission> Permissions { get; set; } = new List<AppPermission>();

    public virtual ICollection<AppUser> Users { get; set; } = new List<AppUser>();
    // 数据权限范围
    public string? DataScope { get; set; } = "Self";
    // 分配权限给角色（避免重复）
    public void AssignPermission(AppPermission permission)
    {
        if (!Permissions.Contains(permission))
        {
            Permissions.Add(permission);
        }
    }

    // 移除角色的某个权限
    public void RemovePermission(AppPermission permission)
    {
        if (Permissions.Contains(permission))
        {
            Permissions.Remove(permission);
        }
    }
    // 判断角色是否拥有指定权限编码
    public bool HasPermission(string permissionCode)
    {
        return Permissions.Any(p => p.Code == permissionCode);
    }

}